package com.session; /**
 * @author wzm
 * @create 2023-05-10 16:38
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/session02")
public class SessionServlet02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //获取Session中的值
        response.setContentType("text/html;charset=utf-8");
        HttpSession session = request.getSession();
        Object key1 = session.getAttribute("key1");//通过key获取值
        response.getWriter().write("我获取的值是："+key1);


    }
}
